package com.fable.web.controller.base;

import com.fable.biz.operate.dto.CustomerDTO;
import com.fable.common.constant.FableConstant;
import com.fable.common.utils.JsonResult;
import com.fable.dal.dto.AdminUserDTO;
import com.fable.dal.model.AdminUserDO;
import com.fable.dal.model.AttributeDO;
import com.fable.utils.CalendarUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.ModelMap;

import javax.servlet.http.HttpServletRequest;
import java.util.*;

/**
 * Created by weishuai on 15/12/15.
 */
public class BaseController {

    private Date start;
    private Date end;




    /**
     * 查询通用部分(如果开始时间和结束时间为空默认查前一天)
     * @param model
     * @param startDateStr
     * @param endDateStr
     * @return
     */
    public void executePre(ModelMap model,String startDateStr, String endDateStr) {

        if (StringUtils.isBlank(startDateStr) && StringUtils.isBlank(endDateStr)) {
            String yesterday = CalendarUtil.formatDate(CalendarUtil.addDate(CalendarUtil.getCurrentDate(), -1), CalendarUtil.DATE_FMT_3);
            start = CalendarUtil.toDate(yesterday + CalendarUtil.TIMEFROM, CalendarUtil.TIME_PATTERN);
            end = CalendarUtil.toDate(yesterday + CalendarUtil.TIMETO, CalendarUtil.TIME_PATTERN);
            startDateStr = CalendarUtil.toString(start, CalendarUtil.DATE_FMT_3);
            endDateStr = startDateStr;
        }

        if (!StringUtils.isBlank(startDateStr) || !StringUtils.isBlank(endDateStr)) {//根据时间段查询
            if (!StringUtils.isBlank(startDateStr) && StringUtils.isBlank(endDateStr)) {
                endDateStr = CalendarUtil.formatDate(CalendarUtil.getCurrentDate(), CalendarUtil.DATE_FMT_3);
            }
            if (!StringUtils.isBlank(startDateStr)) {
                start = CalendarUtil.toDate(startDateStr + CalendarUtil.TIMEFROM, CalendarUtil.TIME_PATTERN);
            }
            end = CalendarUtil.toDate(endDateStr + CalendarUtil.TIMETO, CalendarUtil.TIME_PATTERN);
        }
        model.put("startDateStr",startDateStr);
        model.put("endDateStr",endDateStr);
    }


    public boolean hasPermission(AdminUserDO adminDO, CustomerDTO customerDTO){
        try {

        } catch (Exception e) {
            return true;
        }
        return true;
    }


    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Date getEnd() {
        return end;
    }

    public void setEnd(Date end) {
        this.end = end;
    }
}
